/**
 * short description
 * 
 */
package triangle;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * short description
 *
 * @author wolke
 * @version 1.0, 06.01.2011
 *
 */
public class TriangleTest {

	/**
	 * short description
	 *
	 * @throws java.lang.Exception
	 */
	
	@BeforeClass
	public static void setUpClass() throws Exception {
		System.out.println("Preparing triangle tests before class is instantiated!");
	}
	
	@Before
	public void setUp() throws Exception {
		System.out.println("Preparing triangle tests");
	}

	@Test
	public void testImpossibleTriangles() {
		float impossible_triangles[][] = new float[][] { { 0, 0, 0 },
				{ 0, 2, 3 }, { 2, 0, 5 }, { 3, 4, 0 } }; // list of values
		for (int i = 0; i < impossible_triangles.length; i++) {
			try {
				Triangle t = new Triangle(impossible_triangles[i][0],
						impossible_triangles[i][1], impossible_triangles[i][2]);
				fail(String.format("Impossible triangle was constructed! %s", t
						.toString()));
			} catch (TriangleException e) {
				// TODO Auto-generated catch block
			}
		}
	}	
	
	@Test
	public void testNegativeTriangles() {
		float negative_triangles[][] = new float[][] { { -3, 4, 5 },
				{ 3, -4, 5 }, { 3, 4, -5 }, { -3, -4, -5 } }; // list of values
		for (int i = 0; i < negative_triangles.length; i++) {
			try {
				Triangle t = new Triangle(negative_triangles[i][0],
						negative_triangles[i][1], negative_triangles[i][2]);
				fail(String.format("Impossible triangle was constructed! %s", t
						.toString()));
			} catch (TriangleException e) {
				// TODO Auto-generated catch block
			}
		}
	}
	
	@Test
	public void testIncorrectTriangles() {
		float impossible_triangles[][] = new float[][] { { 3, 3, 9 },
				{ 9, 3, 2}, {(float)3.4, 90, (float)5.7 } }; // list of values
		for (int i = 0; i < impossible_triangles.length; i++) {
			try {
				Triangle t = new Triangle(impossible_triangles[i][0],
						impossible_triangles[i][1], impossible_triangles[i][2]);
				fail(String.format("Impossible triangle was constructed! %s", t
						.toString()));
			} catch (TriangleException e) {
				// TODO Auto-generated catch block
			}
		}
	}	
	
	/**
	 * Test method for {@link triangle.Triangle#Triangle(float, float, float)}.
	 */
	@Test
	public void testCorrectTriangles() throws TriangleException {
		float good_triangles[][] = new float[][] { { 3, 4, 5 },
				{ 5, 5, 5 }, { (float) 3.4, 7, (float) 5.7 }, { 10, 10, 10 },
				{ 1200, (float) 1400.45, (float) 1666.56 } };
		for (int i = 0; i < good_triangles.length; i++) {
			try {
				@SuppressWarnings("unused")
				Triangle t = new Triangle(good_triangles[i][0],
						good_triangles[i][1], good_triangles[i][2]);
				System.out.println(t);
			} catch (TriangleException e) {
				throw e;
			}
		}
	}

	/**
	 * Test method for {@link triangle.Triangle#isIsosceles()}.
	 */
	@Test
	public void testIsIsosceles() throws TriangleException{
		float iso_triangles[][] = new float[][] { { 3, 3, 5 },
				{ 3, 3, 4 }, { 4, 4, 3 },
				{ (float) 5.1, (float) 5.1, (float) 5.1 } }; // list of values
		for (int i = 0; i < iso_triangles.length; i++) {
			try {
				Triangle t = new Triangle(iso_triangles[i][0],
						iso_triangles[i][1], iso_triangles[i][2]);
				if (t.isIsosceles() == false) {
					fail(String.format(
							"Triangle is isosceles but this is not noticed. %s", t
							.toString()));
				}
			} catch (TriangleException e) {
				throw e;
			}
		}
	}

	/**
	 * Test method for {@link triangle.Triangle#isIsosceles()}.
	 */
	@Test
	public void testIsNotIsosceles() throws TriangleException{
		float iso_triangles[][] = new float[][] { { 2, 3, 4 },
				{ 3, 4, 5 } }; // list of values
		for (int i = 0; i < iso_triangles.length; i++) {
			try {
				Triangle t = new Triangle(iso_triangles[i][0],
						iso_triangles[i][1], iso_triangles[i][2]);
				if (t.isIsosceles() == true) {
					fail(String.format(
							"Triangle is not isosceles but this is not noticed. %s", t
							.toString()));
				}
			} catch (TriangleException e) {
				throw e;
			}
		}
	}
	
}


